// test_crawl.go
package main

import (
	"flag"
	"log"
	"time"

	"gitee.com/Flearning/go_crawl/mgobson"
	"gitee.com/Flearning/go_crawl/xueqiu/sh01"
)

var (
	sort  string
	page  int
	soure string
	sleep int
)

func init() {
	flag.IntVar(&sleep, "sleep", 10, "slect crawl data sleep time: `10 ms`")
	flag.IntVar(&page, "page", 1, "select page num :`1`")
	flag.StringVar(&sort, "sort", "alpha", "select crawl data sort: `alpha, time`")
	flag.StringVar(&soure, "soure", "sh000001", "select crawl data soure: `sh000001`")
}

func main() {
	flag.Parse()

	mgobson.NewInit()

	sc := sh01.CrawlInfo{
		Page: page,
		Sort: sort, // alpha || time
	}
	sh01.MgoWSet = true
	sci := sh01.NewCrawlInfo(&sc)
	i := sc.Page
	for {
		time.Sleep(time.Duration(sleep) * time.Millisecond)
		m, n, s := sci.RunCrawl()
		if s > 200 {
			log.Fatal("resp status code :", s)
		}
		sc.Page = n
		i = sc.Page
		log.Println("this page:", sc.Page)
		if i > m {
			break
		}
	}
}
